#include <vector>
#include <iostream>
using namespace std;
int first_duplicate(vector<int> array) 
{
    int duplicateNumber = -1;
    for (int i = 0; i < array.size(); ++i)
    {
        for (int j = i; j < array.size() + 1; ++j)
        {
            if (array[i] == array[j])
            {
                duplicateNumber = array[i];
                return duplicateNumber;
            }
        }
    }
    return duplicateNumber;
}
int main(int argc, char const *argv[])
{
    vector<int> array {1, 1, 2, 3, 5, 5, 8};
    int firstDuplicate = first_duplicate(array);
    cout<<firstDuplicate<<endl;
    return 0;
}
